// input检测

const regEmail = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
const regPhone = /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/;
// 密码 数字字母下划线
const regPassword = /^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_]+$)(?![a-z0-9]+$)(?![a-z\W_]+$)(?![0-9\W_]+$)[a-zA-Z0-9\W_]{8,16}$/;

const checkPhone = (val = "") => {
  let flag = regPhone.test(val);
  if (!flag && val !== "") return 10;
  else if (val === "") return 11;
  else return -1;
};
const checkEmail = (val = "") => {
  let flag = regEmail.test(val);
  if (!flag && val !== "") return 30;
  else if (val === "") return 31;
  else return -1;
};
const checkPassword = (val = "") => {
  let flag = regPassword.test(val);
  if (!flag && val !== "") return 40;
  if (val.length < 8 || val.length > 16) return 40;
  else if (val === "") return 41;
  else return -1;
};
const checkRePassword = (val = "", pass = "") => {
  let flag = regPassword.test(val);
  if (!flag && val !== "") return 40;
  if (val.length < 8 || val.length > 16) return 40;
  else if (val === "") return 51;
  else if (val !== pass) return 50;
  else return -1;
};
const checkCaptcha = (val = "") => {
  if (val !== "") return 20;
  else return -1;
};
const checkFormErrorMsg = val => {
  switch (val) {
    case 10:
      return "请输入正确手机号";
    case 11:
      return "请输入手机号";
    case 20:
      return "请输入验证码";
    case 30:
      return "请输入正确的邮箱";
    case 31:
      return "请输入邮箱";
    case 40:
      return "密码应为大小写字母 数字 特殊字符中的三种！";
    case 41:
      return "请输入密码！";
    case 50:
      return "两次密码不一致！";
    case 51:
      return "请确认输入密码！";
    case 60:
      return "手机号或邮箱输入有误！";
    case 61:
      return "请输入手机号或邮箱！";
    default:
      break;
  }
};
export default {
  checkEmail,
  checkCaptcha,
  checkFormErrorMsg,
  checkPassword,
  checkRePassword,
  checkPhone
};
